package com.nowcoder.community.event;

import com.alibaba.fastjson2.JSONObject;
import com.nowcoder.community.entity.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author 韩
 * @version 1.0
 * 生产者
 * 评论，点赞，关注后主要发送消息
 */
@Component
public class EventProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    //触发事件
    public void fireEvent(Event event) {
        //将事件发送到对应的主题中进行封装处理
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
    }
}
